<template>
	<view class="upload-img">
		<view class="white_b r-10">
			<view class="border method" @click="chooseImage('album')">本地上传</view>
			<view class="method" @click="chooseImage('camera')">拍照上传</view>
		</view>
		<view class="white_b method r-10 cancel" @click="cancel">
			取消
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			count:{
				default:9,
				type:Number
			}
		},
		data(){
			return {
				file:[],
				imgRemote:getApp().globalData.imgRemote
			}
		},
		methods:{
			cancel(){
				this.$emit('cancel')
			},
			chooseImage(type) {
				let _ = this;
				uni.chooseImage({
					count:_.count,
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: [type], //从相册选择
					success(res) {
						let file = res.tempFilePaths;
			
					_.cancel();
						for (let i in file) {
							uni.uploadFile({
								url: getApp().globalData.rootUrl + _.$api.mainUpload, //此处换上你的接口地址
								name: 'file',
								filePath: file[i],
								success: function(res1) {
									_.file = (_.imgRemote + JSON.parse(res1.data).data);
									_.$emit('success',_.file)
								}
							})
						}
			
					}
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.upload-img {
		// width: 690rpx;
		margin: 0 30rpx;
	
		.method {
			height: 109rpx;
			line-height: 109rpx;
			text-align: center;
		}
	
		.cancel {
			margin: 30rpx 0;
		}
	}
</style>
